//
// Created by 29001 on 2024/11/20.
//

#ifndef HANDWRITTEN_SQLITE_REPL_H
#define HANDWRITTEN_SQLITE_REPL_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>
#include <errno.h>
#include <stdint.h>

ssize_t getline(char **lineptr, size_t *n, FILE *stream);

/*
 * the data structure is for input token
 */
typedef struct {
    char *buffer;
    size_t buffer_length;//size_t equals to unsigned long long int
    ssize_t input_length;//ssize_t equals to long long int
} InputBuffer;


/*
 * just initialised a new buffer
 * return the structure of buffer for containing the next input token
 */
InputBuffer *new_input_buffer();

void print_prompt() {
    printf("EYKDB > ");//can be custom
}

/*
 * input the token now!
 * used the getline function
 * two details:
 * 1.replace the enter char with '\0' at the end
 * 2.the real length must minus 1
 */
void read_input(InputBuffer *inputBuffer);

/*
 * free the dynamic memory allocated in the input_buffer(all the point's data should be free)
 */
void close_input_buffer(InputBuffer *input_buffer) {
    free(input_buffer->buffer);
    free(input_buffer);
}

#endif //HANDWRITTEN_SQLITE_REPL_H
